package org.budo.weixin.work.api.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.budo.xml.XmlObject;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * @author lmw
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class WebhookSpRecord implements SpRecord, Serializable {
    private static final long serialVersionUID = -7281392748242361448L;

    private XmlObject xml;

    private Integer index;

    public WebhookSpRecord(XmlObject xml) {
        this.xml = xml;
    }

    public List<SpRecordDetail> getDetails() {
        XmlObject[] details = this.getXml().getChildNodeArrayByName("Details");
        List<SpRecordDetail> list = new ArrayList<SpRecordDetail>();

        for (XmlObject detail : details) {
            WebhookSpRecordDetail spRecordDetail = new WebhookSpRecordDetail(this.getIndex(), detail);
            list.add(spRecordDetail);
        }

        return list;
    }
}

/*
<SpRecord>
<SpStatus>1</SpStatus>
<ApproverAttr>2</ApproverAttr>
<Details>
  <Approver>
    <UserId><![CDATA[LianLin]]></UserId>
  </Approver>
  <Speech><![CDATA[]]></Speech>
  <SpStatus>2</SpStatus>
  <SpTime>1600768824</SpTime>
</Details>
<Details>
  <Approver>
    <UserId><![CDATA[tanyi]]></UserId>
  </Approver>
  <Speech><![CDATA[]]></Speech>
  <SpStatus>1</SpStatus>
  <SpTime>0</SpTime>
</Details>
</SpRecord>
  */
